<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<style>
    .down{cursor: pointer;padding-right: 5px;}
    .hd{display: none;}
</style>
<body class="laytp-container">
    <div style="height: 45px"></div>
    <div id="opt_nav">
    </div>
    <div id="dialog">
        <div class="page-title" id="page-title">
            <div class="page-title-con">
                <span class="title">选择证书信息</span>
                <div class="move_title"></div>
                <div class="page-title-opt-list">
                    <button class="layui-btn layui-btn-sm btn-dark marginr5" type="button" id="submit">确定</button>
                    <span id="page-close" class="page-close" onclick="layer_close()">×</span>
                </div>
            </div>
        </div>
    </div>


    <div class="layui-card" id="search-form">
        <div class="layui-card-body">
            <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-md3">
                            <label class="layui-form-label">所属单位</label>
                            <div class="layui-input-block">
                                <div id="chanid" class="xmselect_div">
                                    <div class="xmselect_title">请选择</div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <label class="layui-form-label">证书名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <label class="layui-form-label">证书编号</label>
                            <div class="layui-input-block">
                                <input type="text" name="number" placeholder="请输入" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">证书形式</label>
                            <div class="layui-input-block">
                                <select name="form" id="form"></select>
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">证书去向</label>
                            <div class="layui-input-block">
                                <select name="goes" id="goes"></select>
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">证书状态</label>
                            <div class="layui-input-block">
                                <select name="status" id="status"></select>
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">发证单位</label>
                            <div class="layui-input-block">
                                <input type="text" name="issue_unit" placeholder="请输入" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">注册/发证日期</label>
                            <div class="layui-input-block">
                                <input type="text" name="issue_dt" placeholder="请输入" class="layui-input bdate_ymd" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">有效期止</label>
                            <div class="layui-input-block">
                                <input type="text" name="expiry_dt" placeholder="请输入" class="layui-input bdate_ymd" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">下次年检时间</label>
                            <div class="layui-input-block">
                                <input type="text" name="inspect_dt" placeholder="请输入" class="layui-input bdate_ymd" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">自编号</label>
                            <div class="layui-input-block">
                                <input type="text" name="zinumber" placeholder="请输入" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">保管人</label>
                            <div class="layui-input-block">
                                <input type="text" name="custodianid" placeholder="请输入" class="layui-input" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-col-md3 search_hide none">
                            <label class="layui-form-label">存放地</label>
                            <div class="layui-input-block">
                                <div id="store_addr" class="xmselect_div">
                                    <div class="xmselect_title">请选择</div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-form-item search-div">
                                <div class="layui-form-item layui-inline">
                                    <input type="hidden" id="type" name="type" value="">
                                    <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                    <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                    <div id="search_open" onclick="toggle_search()">
                                        <i class="layui-icon layui-icon-down"></i>展开
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>


    <div class="layui-card" id="table-card">
        <div class="layui-card-body">
            <div class="layui-row">
                <div class="layui-col-md12" id="table_list">
                    <div class="layui-card-body">
                        <table id="datalist" lay-filter="datalist"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        // 重选设置默认选中
        var oldData = getQueryVariable('old_data');
        var oldDataIdArr = [];
        if(oldData){
            oldDataIdArr = oldData.split(',');
        }
        // 单选多选分类 默认单选 choose_type传值为多选
        var choose_type = getQueryVariable('choose_type');
        if(choose_type === undefined || choose_type === false){
            choose_type = 'radio';
        }else{
            choose_type = 'checkbox';
        }
        // 是否赋值在同一个节点上 默认赋值两个节点
        var input = getQueryVariable('input');
        if(input === undefined || input === false){
            input = 'multi';
        }else{
            input = 'single';
        }

        // 页面绑定节点元素
        var parent_dom = getQueryVariable('dom');
        // 页面分类
        var parent_page = getQueryVariable('page');

        // 传递参数
        var parent_status = getQueryVariable('status');
        if(parent_status === undefined || parent_status === false){
            parent_status = '';
        }
        var parent_goes = getQueryVariable('goes');
        if(parent_goes === undefined || parent_goes === false){
            parent_goes = '';
        }
        var parent_isborrow = getQueryVariable('isborrow') || '';

        var currButAuth, currTabData, treeObj, treeData = [], treeStatus = 2, sea_store_addr=''
            , queryStatus = 0, sea_chanid='';
        layui.use(['table','form','element','facade'],function() {
            var table = layui.table;
            var facade = layui.facade;
            var form = layui.form;

            $('#TableSearchReset').click(function () {
                sea_store_addr='';sea_chanid='';
                $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
                $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
                searchTableFunc(form, table)
            });

            table.render({
                elem: '#datalist'
                ,toolbar: false
                ,defaultToolbar: false
                , height: 'full-140'
                ,method:'post'
                ,url: facade.url(ask_opt_get_cert_company)
                ,page: true
                ,where: {status: parent_status, goes: parent_goes,isborrow:parent_isborrow}
                ,request: {pageName: 'page',limitName: 'pagesize'}
                ,parseData: function(res){

                    if(queryStatus === 0){
                        xiala_zhan_one_you('form', res.data.form, res.data.is_form);
                        xiala_zhan_one_you('state', res.data.state, res.data.is_state);
                        xiala_zhan_one_you('goes', res.data.goes, res.data.is_goes);

                        queryStatus = 1;
                    }

                    xmselect_dan('chanid', res.data.chanid, sea_chanid, function (res) {
                        sea_chanid = res.arr && res.arr.length > 0 ?  res.arr[0].value : '';
                        searchTableFunc(form, table);
                    });
                    xmselect_dan('store_addr', res.data.store_addr, sea_store_addr, function (res) {
                        sea_store_addr = res.arr && res.arr.length > 0 ? res.arr[0].value : '';
                        searchTableFunc(form, table);
                    });

                    render_from();
                    return {
                        "code": res.code,
                        "msg": res.message,
                        "count": res.data.data.total,
                        "data": res.data.data.data
                    };
                }
                ,response: {statusCode: 2000}
                ,cols: [[
                    {type:choose_type,fixed:'left'}
                    ,{type:'numbers',title:'序号',fixed:'left'}
                    ,{field: 'name', title: '证书名称',minWidth: 100,templet:function (e) {
                        if(e.filesnum > 0){
                            if(e.pid === 0){
                                return e.name;
                            }else{
                                return '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[副本]' + e.name;
                            }
                        }else{
                            if(e.pid === 0){
                                return e.name+'&nbsp;&nbsp;<icon class="layui-icon layui-icon-link" title="有附件"></icon>';
                            }else{
                                return '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[副本]' + e.name + '&nbsp;&nbsp;<icon class="layui-icon layui-icon-link" title="有附件"></icon>';
                            }
                        }
                    }}
                    ,{field:'chan_name',title:'所属公司'}
                    ,{field:'number',title:'证书编号'}
                    ,{field:'introduce',title:'证书内容'}
                    ,{field:'zinumber',title:'自编号'}
                    ,{field:'expiry_dt',title:'有效期止'}
                    ,{field:'form',title:'证书形式'}
                    ,{field:'state', title:'证书状态'}
                    ,{field:'goes',title:'证书去向'}
                ]]
                // 重选设置默认选中
                ,done : function(res, curr, count){
                    if( oldDataIdArr ){
                        layui.each(res.data, function(index,item){
                            if( oldDataIdArr.indexOf(''+item.id+'') > -1 ){
                                if(choose_type === 'radio'){
                                    res.data[index]["LAY_CHECKED"] = 'true';
                                    $("div[lay-id='datalist'] tr[data-index=" + index + "]").attr("class", "layui-table-click");
                                    $("div[lay-id='datalist'] tr[data-index=" + index + "]").find(".layui-form-radio").attr("class", "layui-unselect layui-form-radio layui-form-radioed");
                                    $("div[lay-id='datalist'] tr[data-index=" + index + "]").find(".layui-icon").attr("class", "layui-anim layui-icon layui-anim-scaleSpring");
                                    $("div[lay-id='datalist'] tr[data-index=" + index + "] input[type='radio']").next().click();
                                }else if(choose_type === 'checkbox'){
                                    res.data[index]["LAY_CHECKED"] = 'true';
                                    $("div[lay-id='datalist'] tr[data-index=" + index + "] input[type='checkbox']").prop('checked', true);
                                    $("div[lay-id='datalist'] tr[data-index=" + index + "] input[type='checkbox']").next().addClass('layui-form-checked');
                                }
                            }
                        });
                    }
                }
            });

            listTableSearch(form, table);

            // 查询数据-以前的查询条件都会保留
            $('#search').on('click', function(){
                var keyword = $('#keyword').val();
                table.reload('datalist', {
                    page:{curr:1},
                    where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                        keyword:keyword
                    }
                });
            });

            $('#submit').on('click', function () {
                var checkStatus = layui.table.checkStatus('datalist');
                var data = checkStatus.data;
                if(data.length === 0){
                    facade.error('请选择数据'); return false;
                }

                if(parent_page === '页面值'){

                }else if(parent_page === 'cert_down'){
                    var str = '';
                    var nums = $("#list_list tr", parent.document).length;
                    for (var key in data){
                        nums++;
                        str += '<tr>';
                        str += '<td style="width: 45px">'+nums+'</td>';
                        str += '<td>';
                        str += '<input type="text" certid="'+data[key].id+'" certtype="2" disabled value="'+data[key].name+'-'+data[key].chan_name+'" class="layui-input disabled name">';
                        str += '</td>';
                        str += '<td><input type="text" class="layui-input disabled major" disabled></td>';
                        str += '<td><input type="text" class="layui-input disabled number" disabled value="'+data[key].number+'"></td>';
                        str += '<td><input type="text" class="layui-input disabled form" disabled value="'+data[key].form+'"></td>';
                        str += '<td><input type="text" class="layui-input disabled goes" disabled value="'+data[key].goes+'"></td>';
                        str += '<td><input type="text" class="layui-input disabled chanid_name" disabled value="'+data[key].chan_name+'"></td>';
                        str += '</tr>';
                    }
                    $("#list_list", parent.document).append(str);
                    if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                        window.parent.update_refresh_row_func();
                    }
                } else if(parent_page === 'cert_borrow'){
                    var str = '';
                    var nums = $("#list_list tr", parent.document).length;
                    for (var key in data){
                        nums++;
                        str += '<tr>';
                        str += '<td style="width: 45px">'+nums+'</td>';
                        str += '<td>';
                        if(data[key].pid > 0){
                            data[key].name = '[副本]'+data[key].name;
                        }
                        str += '<input type="text" certid="'+data[key].id+'" certtype="2" disabled value="'+data[key].name+'-'+data[key].chan_name+'" class="layui-input disabled name">';
                        str += '</td>';
                        str += '<td><input type="text" class="layui-input disabled major" disabled></td>';
                        str += '<td><input type="text" class="layui-input disabled number" disabled value="'+data[key].number+'"></td>';
                        str += '<td><input type="text" class="layui-input disabled form" disabled value="'+data[key].form+'"></td>';
                        str += '<td><input type="text" class="layui-input disabled goes" disabled value="'+data[key].goes+'"></td>';
                        str += '<td><input type="text" class="layui-input disabled chanid_name" disabled value="'+data[key].chan_name+'"></td>';
                        str += '</tr>';
                    }
                    $("#list_list", parent.document).append(str);
                    if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                        window.parent.update_refresh_row_func();
                    }
                }

                layer_close();
            });

            // 清空
            $('#empty').on('click', function () {
                $("#"+parent_dom+'_name' , parent.document).val('');
                $("#"+parent_dom , parent.document).val('');
                layer_close();
            });
        });
    </script>
</body>
</html>
